<?php

namespace app\stores\middleware;


use app\stores\model\promotion\PromotionmemberModel;

class PromotionCheck{

    use \app\BaseTrait;



    /**

     * 处理请求

     *  验证是否登录是否正确的中间件

     * @param \think\Request $request

     * @param \Closure       $next

     * @return Response

     */

    public function handle($request, \Closure $next)

    {
        $team_id = $request->param('team_id');

        $type = $request->param('type/d',1);

        $member_id = $request->memberId;
        
        $p_member = PromotionmemberModel::info(['is_effect'=>1,'member_id'=>$member_id,'type'=>$type,'team_id'=>$team_id]);

        if(empty($p_member)){
            return $this->error('您未加入该推广团队');
        }

        if($type==2 && $p_member['type']!=2){
            return $this->error('您不是该团队的团长');
        }
        //是否是该团队团长
        $request->isLead=($p_member['type']==2)?1:0;

        $request->teamId=$team_id;

        $request->type=$type;

        return $next($request);

    }

}

